import Vue from 'vue';
import App from './App.vue';
import router from './router';
// 引入vuex
import Vuex from 'vuex';
import store from './vuex/store';
Vue.use(Vuex);
import axios from 'axios';
//全局封装axios请求
Vue.prototype.$axios = axios;

// import api from './api/axios';
// Vue.prototype.$api = api;

Vue.config.productionTip = false;

// 引入vue-amap
import VueAMap from 'vue-amap';
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: '7a914519ce7b2d0234cffdd2f49f5b55',
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor', 'Geocoder', 'MarkerClusterer', 'Geolocation'],
  // 默认高德 sdk 版本为 1.4.4
  v: '1.4.5'
});

// cookie方法
import cookie from 'vue-cookie';
//axios.defaults.auth = {username: ‘test’,password: ‘123456’}
Vue.prototype.$cookies = cookie;

// vant
import { Dialog } from 'vant';
Vue.use(Dialog);
// vant - ui

//公共路径
global.url_g = '/api';

//点击地图上信息窗体的确认按钮
global.mapConfirm = () => {
  Dialog.confirm({
    // title: '确定选择该地址',
    message: '确定选择该地址？'
  }).then(() => {
    // on confirm
    // 跳转页面
    router.push({
      name: 'Publish'
    });
  }).catch(() => {
    // on cancel
  });
};

// 微信登录操作
router.beforeEach(async (to, from, next) => {
  let cookiePhoneNum = cookie.get('phoneNum');
  let toPath = to.path;
  let fromPath = from.path;
  cookie.set('groupLoginUrl', to.fullPath);
  // console.log(to)
  // console.log(from)
  // if (toPath !== '/author' && !cookiePhoneNum) {
  //   // 第一次进入项目
  //   next('/author');
  //   return false;
  // }
  next();
});

new Vue({
  el: '#app',
  router,
  store, //使用store vuex
  template: '<App/>',
  components: {
    App
  }
});
